package org.coderjonny.thread;

import org.springframework.core.NamedInheritableThreadLocal;

import java.util.HashMap;
import java.util.Map;

public class ThreadLocalUtil {
    private static final ThreadLocal<Map<String,Object>> THREAD_LOCAL = new NamedInheritableThreadLocal<Map<String,Object>>("ThreadLocalUtil"){
        @Override
        protected Map<String, Object> initialValue() {
            return new HashMap<>();
        }
    };
    public static final String LOG_ENTITY = "LogEntity";
    public static Object get(String key){
        if (THREAD_LOCAL.get() == null){
            return null;
        }
        return THREAD_LOCAL.get().get(key);
    }
    public static void set(String key,Object value){
        THREAD_LOCAL.get().put(key, value);
    }
    public static Object remove(String key){
        return THREAD_LOCAL.get().remove(key);
    }

}
